<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><title>MySQL常用语句 | 小灰灰博客</title><meta name="keywords" content="php,json,mysql"><meta name="author" content="小灰灰"><meta name="copyright" content="小灰灰"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="常用的语句查询 select * from bbs where id&#x3D;1;  增加 insert into bbs (name,data_year) values (“jack”,”1993-10-01”);  修改 update bbs set name&#x3D;”tom”,sex&#x3D;1,age&#x3D;18 where name&#x3D;”jack”;  删除 del">
<meta property="og:type" content="article">
<meta property="og:title" content="MySQL常用语句">
<meta property="og:url" content="https://www.xiaohuihui.net/posts/adb47c67.html">
<meta property="og:site_name" content="小灰灰博客">
<meta property="og:description" content="常用的语句查询 select * from bbs where id&#x3D;1;  增加 insert into bbs (name,data_year) values (“jack”,”1993-10-01”);  修改 update bbs set name&#x3D;”tom”,sex&#x3D;1,age&#x3D;18 where name&#x3D;”jack”;  删除 del">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://www.sxkawzp.cn/upload/2020/2/mysql1-12a849f2afe54669a6cc3259e9d380ac.jpg">
<meta property="article:published_time" content="2022-04-10T18:46:44.000Z">
<meta property="article:modified_time" content="2022-04-11T03:52:48.360Z">
<meta property="article:author" content="小灰灰">
<meta property="article:tag" content="php">
<meta property="article:tag" content="json">
<meta property="article:tag" content="mysql">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://www.sxkawzp.cn/upload/2020/2/mysql1-12a849f2afe54669a6cc3259e9d380ac.jpg"><link rel="shortcut icon" href="/img/favicon.png"><link rel="canonical" href="https://www.xiaohuihui.net/posts/adb47c67"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//hm.baidu.com"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><meta name="referrer" content="no-referrer"><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.css" media="print" onload="this.media='all'"><script>var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?2a44015be196a2b1f38395c5cb4e4ae5";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: {"path":"search.xml","languages":{"hits_empty":"找不到您查询的内容：${query}"}},
  translate: {"defaultEncoding":2,"translateDelay":0,"msgToTraditionalChinese":"繁","msgToSimplifiedChinese":"簡"},
  noticeOutdate: {"limitDay":500,"position":"top","messagePrev":"该文章已经发布","messageNext":"天了，自从上次更新以来，文章的内容可能已经过时了。"},
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: true,
    post: true
  },
  runtime: '天',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: {"chs_to_cht":"你已切换为繁体","cht_to_chs":"你已切换为简体","day_to_night":"你已切换为深色模式","night_to_day":"你已切换为浅色模式","bgLight":"#49b1f5","bgDark":"#1f1f1f","position":"top-right"},
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery@2/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery@2/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: true,
  isAnchor: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'MySQL常用语句',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2022-04-11 11:52:48'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><meta name="generator" content="Hexo 6.1.0"></head><body><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><div class="spinner-box"><div class="configure-border-1"><div class="configure-core"></div></div><div class="configure-border-2"><div class="configure-core"></div></div><div class="loading-word">加载中...</div></div></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src= "" data-lazy-src="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data is-center"><div class="data-item"><a href="/archives/"><div class="headline">文章</div><div class="length-num">8</div></a></div><div class="data-item"><a href="/tags/"><div class="headline">标签</div><div class="length-num">18</div></a></div><div class="data-item"><a href="/categories/"><div class="headline">分类</div><div class="length-num">3</div></a></div></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div><div class="menus_item"><a class="site-page" href="/messageboard/"><i class="fa-fw fa fa-paper-plane"></i><span> 留言板</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('https://www.sxkawzp.cn/upload/2020/2/mysql1-12a849f2afe54669a6cc3259e9d380ac.jpg')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/">小灰灰博客</a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div><div class="menus_item"><a class="site-page" href="/messageboard/"><i class="fa-fw fa fa-paper-plane"></i><span> 留言板</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">MySQL常用语句</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2022-04-10T18:46:44.000Z" title="发表于 2022-04-11 02:46:44">2022-04-11</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2022-04-11T03:52:48.360Z" title="更新于 2022-04-11 11:52:48">2022-04-11</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E5%AD%A6%E6%97%A0%E6%AD%A2%E5%A2%83/">学无止境</a><i class="fas fa-angle-right post-meta-separator"></i><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/Msql/">Msql</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">1.2k</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>6分钟</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="MySQL常用语句"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><p><img src= "" data-lazy-src="https://cdn.nlark.com/yuque/0/2022/png/27022430/1649645235333-50c0c21c-f619-40d2-a2cc-04e39d484716.png#clientId=u78daabba-49db-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=503&id=u9de5a5e2&margin=%5Bobject%20Object%5D&name=image.png&originHeight=555&originWidth=900&originalType=binary%E2%88%B6=1&rotation=0&showTitle=false&size=116531&status=done&style=none&taskId=uff38ef90-5ac3-4ff7-ad55-dfe5c18811b&title=&width=815.0943689560213" alt="image.png"></p>
<h2 id="常用的语句"><a href="#常用的语句" class="headerlink" title="常用的语句"></a>常用的语句</h2><h3 id="查询"><a href="#查询" class="headerlink" title="查询"></a>查询</h3><blockquote>
<p>select * from bbs where id&#x3D;1;</p>
</blockquote>
<h3 id="增加"><a href="#增加" class="headerlink" title="增加"></a>增加</h3><blockquote>
<p>insert into bbs (name,data_year) values (“jack”,”1993-10-01”);</p>
</blockquote>
<h3 id="修改"><a href="#修改" class="headerlink" title="修改"></a>修改</h3><blockquote>
<p>update bbs set name&#x3D;”tom”,sex&#x3D;1,age&#x3D;18 where name&#x3D;”jack”;</p>
</blockquote>
<h3 id="删除"><a href="#删除" class="headerlink" title="删除"></a>删除</h3><blockquote>
<p>delete form bbs where id&#x3D;2;</p>
</blockquote>
<h2 id="更多语句"><a href="#更多语句" class="headerlink" title="更多语句"></a>更多语句</h2><h3 id="进入数据库："><a href="#进入数据库：" class="headerlink" title="进入数据库："></a>进入数据库：</h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">mysql <span class="operator">-</span>u root <span class="operator">-</span>p</span><br><span class="line">mysql <span class="operator">-</span>h localhost <span class="operator">-</span>u root <span class="operator">-</span>p database_name</span><br></pre></td></tr></table></figure>

<h3 id="列出数据库："><a href="#列出数据库：" class="headerlink" title="列出数据库："></a>列出数据库：</h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">show</span> databases;</span><br></pre></td></tr></table></figure>

<h3 id="选择数据库："><a href="#选择数据库：" class="headerlink" title="选择数据库："></a>选择数据库：</h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">use databases_name;</span><br></pre></td></tr></table></figure>

<h3 id="列出数据表："><a href="#列出数据表：" class="headerlink" title="列出数据表："></a>列出数据表：</h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">show</span> tables;</span><br></pre></td></tr></table></figure>

<h3 id="显示表格列的属性："><a href="#显示表格列的属性：" class="headerlink" title="显示表格列的属性："></a>显示表格列的属性：</h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">show</span> columns <span class="keyword">from</span> table_name;</span><br><span class="line"><span class="keyword">describe</span> table_name;</span><br></pre></td></tr></table></figure>

<h3 id="导出整个数据库："><a href="#导出整个数据库：" class="headerlink" title="导出整个数据库："></a>导出整个数据库：</h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">mysqldump <span class="operator">-</span>u user_name <span class="operator">-</span>p database_name <span class="operator">&gt;</span> <span class="operator">/</span>tmp<span class="operator">/</span>file_name</span><br></pre></td></tr></table></figure>

<blockquote>
<p>例如：mysqldump -u root -p test_db &gt; d:&#x2F;test_db.sql</p>
</blockquote>
<h3 id="导出一个表："><a href="#导出一个表：" class="headerlink" title="导出一个表："></a>导出一个表：</h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">mysqldump <span class="operator">-</span>u user_name <span class="operator">-</span>p database_name table_name <span class="operator">&gt;</span> <span class="operator">/</span>tmp<span class="operator">/</span>file_name</span><br></pre></td></tr></table></figure>

<blockquote>
<p>例如：mysqldump -u root -p test_db table1 &gt; d:&#x2F;table1.sql</p>
</blockquote>
<h3 id="导出一个数据库结构："><a href="#导出一个数据库结构：" class="headerlink" title="导出一个数据库结构："></a>导出一个数据库结构：</h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">mysqldump <span class="operator">-</span>u user_name <span class="operator">-</span>p <span class="operator">-</span>d <span class="comment">--add--table database_name &gt; file_name</span></span><br></pre></td></tr></table></figure>

<blockquote>
<p>例如：mysqldump -u root -p -d –add-drop-table test_db &gt; test_db.sql</p>
</blockquote>
<h3 id="导入数据库："><a href="#导入数据库：" class="headerlink" title="导入数据库："></a>导入数据库：</h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">source file_name;</span><br><span class="line"># 或者</span><br><span class="line">mysql <span class="operator">-</span>u user_name <span class="operator">-</span>p database_name <span class="operator">&lt;</span> file_name</span><br></pre></td></tr></table></figure>

<blockquote>
<p>例如：<br>source &#x2F;tmp&#x2F;bbs.sql；<br>source d:&#x2F;bbs.sql；<br>mysql -u root -p bbs &lt; “d:&#x2F;bbs.sql”<br>mysql -u root -p bbs &lt; “&#x2F;tmp&#x2F;bbs.sql”</p>
</blockquote>
<h3 id="将文本文件导入数据表中（excel-与之相同）"><a href="#将文本文件导入数据表中（excel-与之相同）" class="headerlink" title="将文本文件导入数据表中（excel 与之相同）"></a>将文本文件导入数据表中（excel 与之相同）</h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">load data infile &quot;tables.txt&quot; <span class="keyword">into</span> <span class="keyword">table</span> table_name;</span><br></pre></td></tr></table></figure>

<blockquote>
<p>例如：<br>load data infile “&#x2F;tmp&#x2F;bbs.txt” into table bbs；<br>load data infile “&#x2F;tmp&#x2F;bbs.xls” into table bbs；<br>load data infile “d:&#x2F;bbs.txt” into table bbs；<br>load data infile “d:&#x2F;bbs.xls” into table bbs；</p>
</blockquote>
<h3 id="将数据表导出为文本文件（excel-与之相同）"><a href="#将数据表导出为文本文件（excel-与之相同）" class="headerlink" title="将数据表导出为文本文件（excel 与之相同）"></a>将数据表导出为文本文件（excel 与之相同）</h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> <span class="operator">*</span> <span class="keyword">into</span> outfile &quot;path_file_name&quot; <span class="keyword">from</span> table_name;</span><br></pre></td></tr></table></figure>

<blockquote>
<p>例如：<br>select _ into outfile “&#x2F;tmp&#x2F;bbs.txt” from bbs；<br>select _ into outfile “&#x2F;tmp&#x2F;bbs.xls” from bbs where id&#x3D;1;<br>select _ into outfile “d:&#x2F;bbs.txt” from bbs;<br>select _ into outfile “d:&#x2F;bbs.xls” from bbs where id&#x3D;1;</p>
</blockquote>
<h3 id="创建数据库时先判断数据库是否存在："><a href="#创建数据库时先判断数据库是否存在：" class="headerlink" title="创建数据库时先判断数据库是否存在："></a>创建数据库时先判断数据库是否存在：</h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">create</span> database if <span class="keyword">not</span> <span class="keyword">exists</span> database_name;</span><br></pre></td></tr></table></figure>

<blockquote>
<p>例如：create database if not exists bbs</p>
</blockquote>
<h3 id="创建数据库："><a href="#创建数据库：" class="headerlink" title="创建数据库："></a>创建数据库：</h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">create</span> database database_name;</span><br></pre></td></tr></table></figure>

<blockquote>
<p>例如：create database bbs;</p>
</blockquote>
<h3 id="删除数据库："><a href="#删除数据库：" class="headerlink" title="删除数据库："></a>删除数据库：</h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">drop</span> database database_name;</span><br></pre></td></tr></table></figure>

<blockquote>
<p>例如：drop database bbs;</p>
</blockquote>
<h3 id="创建数据表："><a href="#创建数据表：" class="headerlink" title="创建数据表："></a>创建数据表：</h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">mysql<span class="operator">&gt;</span> <span class="keyword">create</span> <span class="keyword">table</span> <span class="operator">&lt;</span>table_name<span class="operator">&gt;</span> ( <span class="operator">&lt;</span><span class="keyword">column</span> <span class="number">1</span> name<span class="operator">&gt;</span> <span class="operator">&lt;</span>col. <span class="number">1</span> type<span class="operator">&gt;</span> <span class="operator">&lt;</span>col. <span class="number">1</span> details<span class="operator">&gt;</span>,<span class="operator">&lt;</span><span class="keyword">column</span> <span class="number">2</span> name<span class="operator">&gt;</span> <span class="operator">&lt;</span>col. <span class="number">2</span> type<span class="operator">&gt;</span> <span class="operator">&lt;</span>col. <span class="number">2</span> details<span class="operator">&gt;</span>, ...);</span><br></pre></td></tr></table></figure>

<blockquote>
<p>例如：create table (id int not null auto_increment primary key,name char(16) not null default “jack”,date_year date not null);</p>
</blockquote>
<h3 id="删除数据表中数据："><a href="#删除数据表中数据：" class="headerlink" title="删除数据表中数据："></a>删除数据表中数据：</h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">delete</span> <span class="keyword">from</span> table_name;</span><br></pre></td></tr></table></figure>

<blockquote>
<p>例如：<br>delete from bbs;<br>delete from bbs where id&#x3D;2;</p>
</blockquote>
<h3 id="删除数据库中的数据表："><a href="#删除数据库中的数据表：" class="headerlink" title="删除数据库中的数据表："></a>删除数据库中的数据表：</h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">drop</span> <span class="keyword">table</span> table_name;</span><br></pre></td></tr></table></figure>

<blockquote>
<p>例如：<br>drop table test_db;<br>rm -f database_name&#x2F;table_name._ (linux 下）<br>例如：<br>rm -rf bbs&#x2F;accp._</p>
</blockquote>
<h3 id="向数据库中添加数据："><a href="#向数据库中添加数据：" class="headerlink" title="向数据库中添加数据："></a>向数据库中添加数据：</h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">insert</span> <span class="keyword">into</span> table_name <span class="keyword">set</span> column_name1<span class="operator">=</span>value1,column_name2<span class="operator">=</span>value2;</span><br></pre></td></tr></table></figure>

<blockquote>
<p>例如：insert into bbs set name&#x3D;”jack”,date_year&#x3D;”1993-10-01”;</p>
</blockquote>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">insert</span> <span class="keyword">into</span> table_name <span class="keyword">values</span> (column1,column2,...);</span><br></pre></td></tr></table></figure>

<blockquote>
<p>例如：insert into bbs (“2”,”jack”,”1993-10-02”)</p>
</blockquote>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">insert</span> <span class="keyword">into</span> table_name (column_name1,column_name2,...) <span class="keyword">values</span> (value1,value2);</span><br></pre></td></tr></table></figure>

<blockquote>
<p>例如：insert into bbs (name,data_year) values (“jack”,”1993-10-01”);</p>
</blockquote>
<h3 id="查询数据表中的数据："><a href="#查询数据表中的数据：" class="headerlink" title="查询数据表中的数据："></a>查询数据表中的数据：</h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> <span class="operator">*</span> <span class="keyword">from</span> table_name;</span><br></pre></td></tr></table></figure>

<blockquote>
<p>例如：select * from bbs where id&#x3D;1;</p>
</blockquote>
<h3 id="修改数据表中的数据："><a href="#修改数据表中的数据：" class="headerlink" title="修改数据表中的数据："></a>修改数据表中的数据：</h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">update</span> table_name <span class="keyword">set</span> col_name<span class="operator">=</span>new_value <span class="keyword">where</span> id<span class="operator">=</span><span class="number">1</span>;</span><br></pre></td></tr></table></figure>

<blockquote>
<p>例如：update bbs set name&#x3D;”tom”,age&#x3D;18 where name&#x3D;”jack”;</p>
</blockquote>
<h3 id="增加一个字段："><a href="#增加一个字段：" class="headerlink" title="增加一个字段："></a>增加一个字段：</h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">alter</span> <span class="keyword">table</span> table_name <span class="keyword">add</span> <span class="keyword">column</span> field_name datatype <span class="keyword">not</span> <span class="keyword">null</span> <span class="keyword">default</span> &quot;1&quot;;</span><br></pre></td></tr></table></figure>

<blockquote>
<p>例如：alter table bbs add column tel char(16) not null;</p>
</blockquote>
<h3 id="增加多个字段：-column-可省略不写）"><a href="#增加多个字段：-column-可省略不写）" class="headerlink" title="增加多个字段：(column 可省略不写）"></a>增加多个字段：(column 可省略不写）</h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">alter</span> <span class="keyword">table</span> table_name <span class="keyword">add</span> <span class="keyword">column</span> filed_name1 datatype,<span class="keyword">add</span> <span class="keyword">column</span> filed_name2 datatype;</span><br></pre></td></tr></table></figure>

<blockquote>
<p>例如：alter table bbs add column tel char(16) not null,add column address text;</p>
</blockquote>
<h3 id="删除一个字段："><a href="#删除一个字段：" class="headerlink" title="删除一个字段："></a>删除一个字段：</h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">alter</span> <span class="keyword">table</span> table_name <span class="keyword">drop</span> field_name;</span><br></pre></td></tr></table></figure>

<blockquote>
<p>例如：alter table bbs drop tel;</p>
</blockquote>
<h3 id="修改字段的数据类型："><a href="#修改字段的数据类型：" class="headerlink" title="修改字段的数据类型："></a>修改字段的数据类型：</h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span> <span class="keyword">alter</span> <span class="keyword">table</span> table_name modify id <span class="type">int</span> unsigned;</span><br><span class="line">#修改列id的类型为<span class="type">int</span> unsigned</span><br><span class="line"><span class="number">2.</span> <span class="keyword">alter</span> <span class="keyword">table</span> table_name change id sid <span class="type">int</span> unsigned;</span><br><span class="line">#修改列id的名字为sid，而且把属性修改为<span class="type">int</span> unsigned</span><br></pre></td></tr></table></figure>

<h3 id="修改一个字段的默认值："><a href="#修改一个字段的默认值：" class="headerlink" title="修改一个字段的默认值："></a>修改一个字段的默认值：</h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">alter</span> <span class="keyword">table</span> table_name modify column_name datatype <span class="keyword">not</span> <span class="keyword">null</span> <span class="keyword">default</span> &quot;&quot;;</span><br></pre></td></tr></table></figure>

<blockquote>
<p>例如：alter table test_db modify name char(16) default not null “yourname”;</p>
</blockquote>
<h3 id="对表重新命名："><a href="#对表重新命名：" class="headerlink" title="对表重新命名："></a>对表重新命名：</h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">alter</span> <span class="keyword">table</span> table_name rename <span class="keyword">as</span> new_table_name;</span><br></pre></td></tr></table></figure>

<blockquote>
<p>例如：alter table bbs rename as bbs_table;</p>
</blockquote>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">rename <span class="keyword">table</span> old_table_name <span class="keyword">to</span> new_table_name;</span><br></pre></td></tr></table></figure>

<blockquote>
<p>例如：rename table test_db to accp;</p>
</blockquote>
<h3 id="从已经有的表中复制表的结构："><a href="#从已经有的表中复制表的结构：" class="headerlink" title="从已经有的表中复制表的结构："></a>从已经有的表中复制表的结构：</h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">create</span> <span class="keyword">table</span> table2 <span class="keyword">select</span> <span class="operator">*</span> <span class="keyword">from</span> table1 <span class="keyword">where</span> <span class="number">1</span><span class="operator">&lt;&gt;</span><span class="number">1</span>;</span><br></pre></td></tr></table></figure>

<blockquote>
<p>例如：create table test_db select * from accp where 1&lt;&gt;1;</p>
</blockquote>
<h3 id="查询时间："><a href="#查询时间：" class="headerlink" title="查询时间："></a>查询时间：</h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> now();</span><br></pre></td></tr></table></figure>

<h3 id="查询当前用户："><a href="#查询当前用户：" class="headerlink" title="查询当前用户："></a>查询当前用户：</h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> <span class="keyword">user</span>();</span><br></pre></td></tr></table></figure>

<h3 id="查询数据库版本："><a href="#查询数据库版本：" class="headerlink" title="查询数据库版本："></a>查询数据库版本：</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">select version();</span><br></pre></td></tr></table></figure>

<h3 id="创建索引："><a href="#创建索引：" class="headerlink" title="创建索引："></a>创建索引：</h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">alter</span> <span class="keyword">table</span> table1 <span class="keyword">add</span> index ind_id(id);</span><br><span class="line"><span class="keyword">create</span> index ind_id <span class="keyword">on</span> table1(id);</span><br><span class="line"><span class="keyword">create</span> <span class="keyword">unique</span> index ind_id <span class="keyword">on</span> table1(id);<span class="operator">/</span><span class="operator">/</span>建立唯一性索引</span><br></pre></td></tr></table></figure>

<h3 id="删除索引："><a href="#删除索引：" class="headerlink" title="删除索引："></a>删除索引：</h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">drop</span> index idx_id <span class="keyword">on</span> table1;</span><br><span class="line"><span class="keyword">alter</span> <span class="keyword">table</span> table1 <span class="keyword">drop</span> index ind_id;</span><br></pre></td></tr></table></figure>

<h3 id="联合字符或者多个列（将-id-与”-”和列-name-和”-x3D-”连接）"><a href="#联合字符或者多个列（将-id-与”-”和列-name-和”-x3D-”连接）" class="headerlink" title="联合字符或者多个列（将 id 与”:”和列 name 和”&#x3D;”连接）"></a>联合字符或者多个列（将 id 与”:”和列 name 和”&#x3D;”连接）</h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> concat(id，<span class="string">&#x27;:&#x27;</span>,name,<span class="string">&#x27;=&#x27;</span>) <span class="keyword">from</span> <span class="keyword">table</span>;</span><br></pre></td></tr></table></figure>

<h3 id="limit（选出-10-到-20-条）"><a href="#limit（选出-10-到-20-条）" class="headerlink" title="limit（选出 10 到 20 条）"></a>limit（选出 10 到 20 条）</h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> <span class="operator">*</span> <span class="keyword">from</span> bbs <span class="keyword">order</span> <span class="keyword">by</span> id limit <span class="number">9</span>,<span class="number">10</span>;</span><br></pre></td></tr></table></figure>

<blockquote>
<p>（从查询结果中列出第几到几条的记录）</p>
</blockquote>
<h3 id="增加一个管理员账号："><a href="#增加一个管理员账号：" class="headerlink" title="增加一个管理员账号："></a>增加一个管理员账号：</h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">grant</span> <span class="keyword">all</span> <span class="keyword">on</span> <span class="operator">*</span>.<span class="operator">*</span> <span class="keyword">to</span> <span class="keyword">user</span><span class="variable">@localhost</span> identified <span class="keyword">by</span> &quot;password&quot;;</span><br></pre></td></tr></table></figure>

<h3 id="创建表是先判断表是否存在"><a href="#创建表是先判断表是否存在" class="headerlink" title="创建表是先判断表是否存在"></a>创建表是先判断表是否存在</h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">create</span> <span class="keyword">table</span> if <span class="keyword">not</span> <span class="keyword">exists</span> students(……);</span><br></pre></td></tr></table></figure>

<h3 id="复制表："><a href="#复制表：" class="headerlink" title="复制表："></a>复制表：</h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">create</span> <span class="keyword">table</span> table2 <span class="keyword">select</span> <span class="operator">*</span> <span class="keyword">from</span> table1;</span><br></pre></td></tr></table></figure>

<blockquote>
<p>例如：create table test_db select * from accp;</p>
</blockquote>
<h3 id="授于用户远程访问-mysql-的权限"><a href="#授于用户远程访问-mysql-的权限" class="headerlink" title="授于用户远程访问 mysql 的权限"></a>授于用户远程访问 mysql 的权限</h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">grant</span> <span class="keyword">all</span> privileges <span class="keyword">on</span> <span class="operator">*</span>.<span class="operator">*</span> <span class="keyword">to</span> &quot;root&quot;@&quot;%&quot; identified <span class="keyword">by</span> &quot;password&quot; <span class="keyword">with</span> <span class="keyword">grant</span> option;</span><br><span class="line"># 或者是修改mysql数据库中的<span class="keyword">user</span>表中的host字段</span><br><span class="line">use mysql;</span><br><span class="line"><span class="keyword">select</span> <span class="keyword">user</span>,host <span class="keyword">from</span> <span class="keyword">user</span>;</span><br><span class="line"><span class="keyword">update</span> <span class="keyword">user</span> <span class="keyword">set</span> host<span class="operator">=</span>&quot;%&quot; <span class="keyword">where</span> <span class="keyword">user</span><span class="operator">=</span>&quot;user_name&quot;;</span><br></pre></td></tr></table></figure>

<h3 id="查看当前状态"><a href="#查看当前状态" class="headerlink" title="查看当前状态"></a>查看当前状态</h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">show</span> status;</span><br></pre></td></tr></table></figure>

<h3 id="查看当前连接的用户"><a href="#查看当前连接的用户" class="headerlink" title="查看当前连接的用户"></a>查看当前连接的用户</h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">show</span> processlist;</span><br></pre></td></tr></table></figure>

<blockquote>
<p>（如果是 root 用户，则查看全部的线程，得到的用户连接数同 show status;里的 Threads_connected 值是相同的）!</p>
</blockquote>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="https://www.xiaohuihui.net">小灰灰</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://www.xiaohuihui.net/posts/adb47c67.html">https://www.xiaohuihui.net/posts/adb47c67.html</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://www.xiaohuihui.net" target="_blank">小灰灰博客</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/php/">php</a><a class="post-meta__tags" href="/tags/json/">json</a><a class="post-meta__tags" href="/tags/mysql/">mysql</a></div><div class="post_share"><div class="social-share" data-image="https://www.sxkawzp.cn/upload/2020/2/mysql1-12a849f2afe54669a6cc3259e9d380ac.jpg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/social-share.js/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/social-share.js/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="next-post pull-full"><a href="/posts/e8f88cd9.html"><img class="next-cover" src= "" data-lazy-src="/img/default_list.jpg" onerror="onerror=null;src='/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">php json 处理gbk转码utf-8问题（ json_encode转换数组，值为null）</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>相关推荐</span></div><div class="relatedPosts-list"><div><a href="/posts/e8f88cd9.html" title="php json 处理gbk转码utf-8问题（ json_encode转换数组，值为null）"><img class="cover" src= "" data-lazy-src="/img/default_list.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2022-04-11</div><div class="title">php json 处理gbk转码utf-8问题（ json_encode转换数组，值为null）</div></div></a></div></div></div><hr/><div id="post-comment"><div class="comment-head"><div class="comment-headline"><i class="fas fa-comments fa-fw"></i><span> 评论</span></div></div><div class="comment-wrap"><div><div class="vcomment" id="vcomment"></div></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src= "" data-lazy-src="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">小灰灰</div><div class="author-info__description">小灰灰的精神驿站</div></div><div class="card-info-data is-center"><div class="card-info-data-item"><a href="/archives/"><div class="headline">文章</div><div class="length-num">8</div></a></div><div class="card-info-data-item"><a href="/tags/"><div class="headline">标签</div><div class="length-num">18</div></a></div><div class="card-info-data-item"><a href="/categories/"><div class="headline">分类</div><div class="length-num">3</div></a></div></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://www.xiaohuihui.net.cn"><i class="fab fa-gitee"></i><span>Follow Me</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://gitee.com/xianrenqh/huihui-blog-hexo" target="_blank" title=""><i class="fab fa-gitee"></i></a><a class="social-icon" href="mailto:762229008@qq.com" target="_blank" title="Email"><i class="fas fa-envelope"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content">Welcome To My Blog</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content is-expand"><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%B8%B8%E7%94%A8%E7%9A%84%E8%AF%AD%E5%8F%A5"><span class="toc-number">1.</span> <span class="toc-text">常用的语句</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%9F%A5%E8%AF%A2"><span class="toc-number">1.1.</span> <span class="toc-text">查询</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%A2%9E%E5%8A%A0"><span class="toc-number">1.2.</span> <span class="toc-text">增加</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BF%AE%E6%94%B9"><span class="toc-number">1.3.</span> <span class="toc-text">修改</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%88%A0%E9%99%A4"><span class="toc-number">1.4.</span> <span class="toc-text">删除</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%9B%B4%E5%A4%9A%E8%AF%AD%E5%8F%A5"><span class="toc-number">2.</span> <span class="toc-text">更多语句</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%BF%9B%E5%85%A5%E6%95%B0%E6%8D%AE%E5%BA%93%EF%BC%9A"><span class="toc-number">2.1.</span> <span class="toc-text">进入数据库：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%88%97%E5%87%BA%E6%95%B0%E6%8D%AE%E5%BA%93%EF%BC%9A"><span class="toc-number">2.2.</span> <span class="toc-text">列出数据库：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E9%80%89%E6%8B%A9%E6%95%B0%E6%8D%AE%E5%BA%93%EF%BC%9A"><span class="toc-number">2.3.</span> <span class="toc-text">选择数据库：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%88%97%E5%87%BA%E6%95%B0%E6%8D%AE%E8%A1%A8%EF%BC%9A"><span class="toc-number">2.4.</span> <span class="toc-text">列出数据表：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%98%BE%E7%A4%BA%E8%A1%A8%E6%A0%BC%E5%88%97%E7%9A%84%E5%B1%9E%E6%80%A7%EF%BC%9A"><span class="toc-number">2.5.</span> <span class="toc-text">显示表格列的属性：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%AF%BC%E5%87%BA%E6%95%B4%E4%B8%AA%E6%95%B0%E6%8D%AE%E5%BA%93%EF%BC%9A"><span class="toc-number">2.6.</span> <span class="toc-text">导出整个数据库：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%AF%BC%E5%87%BA%E4%B8%80%E4%B8%AA%E8%A1%A8%EF%BC%9A"><span class="toc-number">2.7.</span> <span class="toc-text">导出一个表：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%AF%BC%E5%87%BA%E4%B8%80%E4%B8%AA%E6%95%B0%E6%8D%AE%E5%BA%93%E7%BB%93%E6%9E%84%EF%BC%9A"><span class="toc-number">2.8.</span> <span class="toc-text">导出一个数据库结构：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%AF%BC%E5%85%A5%E6%95%B0%E6%8D%AE%E5%BA%93%EF%BC%9A"><span class="toc-number">2.9.</span> <span class="toc-text">导入数据库：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%B0%86%E6%96%87%E6%9C%AC%E6%96%87%E4%BB%B6%E5%AF%BC%E5%85%A5%E6%95%B0%E6%8D%AE%E8%A1%A8%E4%B8%AD%EF%BC%88excel-%E4%B8%8E%E4%B9%8B%E7%9B%B8%E5%90%8C%EF%BC%89"><span class="toc-number">2.10.</span> <span class="toc-text">将文本文件导入数据表中（excel 与之相同）</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%B0%86%E6%95%B0%E6%8D%AE%E8%A1%A8%E5%AF%BC%E5%87%BA%E4%B8%BA%E6%96%87%E6%9C%AC%E6%96%87%E4%BB%B6%EF%BC%88excel-%E4%B8%8E%E4%B9%8B%E7%9B%B8%E5%90%8C%EF%BC%89"><span class="toc-number">2.11.</span> <span class="toc-text">将数据表导出为文本文件（excel 与之相同）</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%88%9B%E5%BB%BA%E6%95%B0%E6%8D%AE%E5%BA%93%E6%97%B6%E5%85%88%E5%88%A4%E6%96%AD%E6%95%B0%E6%8D%AE%E5%BA%93%E6%98%AF%E5%90%A6%E5%AD%98%E5%9C%A8%EF%BC%9A"><span class="toc-number">2.12.</span> <span class="toc-text">创建数据库时先判断数据库是否存在：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%88%9B%E5%BB%BA%E6%95%B0%E6%8D%AE%E5%BA%93%EF%BC%9A"><span class="toc-number">2.13.</span> <span class="toc-text">创建数据库：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%88%A0%E9%99%A4%E6%95%B0%E6%8D%AE%E5%BA%93%EF%BC%9A"><span class="toc-number">2.14.</span> <span class="toc-text">删除数据库：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%88%9B%E5%BB%BA%E6%95%B0%E6%8D%AE%E8%A1%A8%EF%BC%9A"><span class="toc-number">2.15.</span> <span class="toc-text">创建数据表：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%88%A0%E9%99%A4%E6%95%B0%E6%8D%AE%E8%A1%A8%E4%B8%AD%E6%95%B0%E6%8D%AE%EF%BC%9A"><span class="toc-number">2.16.</span> <span class="toc-text">删除数据表中数据：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%88%A0%E9%99%A4%E6%95%B0%E6%8D%AE%E5%BA%93%E4%B8%AD%E7%9A%84%E6%95%B0%E6%8D%AE%E8%A1%A8%EF%BC%9A"><span class="toc-number">2.17.</span> <span class="toc-text">删除数据库中的数据表：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%90%91%E6%95%B0%E6%8D%AE%E5%BA%93%E4%B8%AD%E6%B7%BB%E5%8A%A0%E6%95%B0%E6%8D%AE%EF%BC%9A"><span class="toc-number">2.18.</span> <span class="toc-text">向数据库中添加数据：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%9F%A5%E8%AF%A2%E6%95%B0%E6%8D%AE%E8%A1%A8%E4%B8%AD%E7%9A%84%E6%95%B0%E6%8D%AE%EF%BC%9A"><span class="toc-number">2.19.</span> <span class="toc-text">查询数据表中的数据：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BF%AE%E6%94%B9%E6%95%B0%E6%8D%AE%E8%A1%A8%E4%B8%AD%E7%9A%84%E6%95%B0%E6%8D%AE%EF%BC%9A"><span class="toc-number">2.20.</span> <span class="toc-text">修改数据表中的数据：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%A2%9E%E5%8A%A0%E4%B8%80%E4%B8%AA%E5%AD%97%E6%AE%B5%EF%BC%9A"><span class="toc-number">2.21.</span> <span class="toc-text">增加一个字段：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%A2%9E%E5%8A%A0%E5%A4%9A%E4%B8%AA%E5%AD%97%E6%AE%B5%EF%BC%9A-column-%E5%8F%AF%E7%9C%81%E7%95%A5%E4%B8%8D%E5%86%99%EF%BC%89"><span class="toc-number">2.22.</span> <span class="toc-text">增加多个字段：(column 可省略不写）</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%88%A0%E9%99%A4%E4%B8%80%E4%B8%AA%E5%AD%97%E6%AE%B5%EF%BC%9A"><span class="toc-number">2.23.</span> <span class="toc-text">删除一个字段：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BF%AE%E6%94%B9%E5%AD%97%E6%AE%B5%E7%9A%84%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B%EF%BC%9A"><span class="toc-number">2.24.</span> <span class="toc-text">修改字段的数据类型：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BF%AE%E6%94%B9%E4%B8%80%E4%B8%AA%E5%AD%97%E6%AE%B5%E7%9A%84%E9%BB%98%E8%AE%A4%E5%80%BC%EF%BC%9A"><span class="toc-number">2.25.</span> <span class="toc-text">修改一个字段的默认值：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%AF%B9%E8%A1%A8%E9%87%8D%E6%96%B0%E5%91%BD%E5%90%8D%EF%BC%9A"><span class="toc-number">2.26.</span> <span class="toc-text">对表重新命名：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BB%8E%E5%B7%B2%E7%BB%8F%E6%9C%89%E7%9A%84%E8%A1%A8%E4%B8%AD%E5%A4%8D%E5%88%B6%E8%A1%A8%E7%9A%84%E7%BB%93%E6%9E%84%EF%BC%9A"><span class="toc-number">2.27.</span> <span class="toc-text">从已经有的表中复制表的结构：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%9F%A5%E8%AF%A2%E6%97%B6%E9%97%B4%EF%BC%9A"><span class="toc-number">2.28.</span> <span class="toc-text">查询时间：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%9F%A5%E8%AF%A2%E5%BD%93%E5%89%8D%E7%94%A8%E6%88%B7%EF%BC%9A"><span class="toc-number">2.29.</span> <span class="toc-text">查询当前用户：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%9F%A5%E8%AF%A2%E6%95%B0%E6%8D%AE%E5%BA%93%E7%89%88%E6%9C%AC%EF%BC%9A"><span class="toc-number">2.30.</span> <span class="toc-text">查询数据库版本：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%88%9B%E5%BB%BA%E7%B4%A2%E5%BC%95%EF%BC%9A"><span class="toc-number">2.31.</span> <span class="toc-text">创建索引：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%88%A0%E9%99%A4%E7%B4%A2%E5%BC%95%EF%BC%9A"><span class="toc-number">2.32.</span> <span class="toc-text">删除索引：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%81%94%E5%90%88%E5%AD%97%E7%AC%A6%E6%88%96%E8%80%85%E5%A4%9A%E4%B8%AA%E5%88%97%EF%BC%88%E5%B0%86-id-%E4%B8%8E%E2%80%9D-%E2%80%9D%E5%92%8C%E5%88%97-name-%E5%92%8C%E2%80%9D-x3D-%E2%80%9D%E8%BF%9E%E6%8E%A5%EF%BC%89"><span class="toc-number">2.33.</span> <span class="toc-text">联合字符或者多个列（将 id 与”:”和列 name 和”&#x3D;”连接）</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#limit%EF%BC%88%E9%80%89%E5%87%BA-10-%E5%88%B0-20-%E6%9D%A1%EF%BC%89"><span class="toc-number">2.34.</span> <span class="toc-text">limit（选出 10 到 20 条）</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%A2%9E%E5%8A%A0%E4%B8%80%E4%B8%AA%E7%AE%A1%E7%90%86%E5%91%98%E8%B4%A6%E5%8F%B7%EF%BC%9A"><span class="toc-number">2.35.</span> <span class="toc-text">增加一个管理员账号：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%88%9B%E5%BB%BA%E8%A1%A8%E6%98%AF%E5%85%88%E5%88%A4%E6%96%AD%E8%A1%A8%E6%98%AF%E5%90%A6%E5%AD%98%E5%9C%A8"><span class="toc-number">2.36.</span> <span class="toc-text">创建表是先判断表是否存在</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%A4%8D%E5%88%B6%E8%A1%A8%EF%BC%9A"><span class="toc-number">2.37.</span> <span class="toc-text">复制表：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%8E%88%E4%BA%8E%E7%94%A8%E6%88%B7%E8%BF%9C%E7%A8%8B%E8%AE%BF%E9%97%AE-mysql-%E7%9A%84%E6%9D%83%E9%99%90"><span class="toc-number">2.38.</span> <span class="toc-text">授于用户远程访问 mysql 的权限</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%9F%A5%E7%9C%8B%E5%BD%93%E5%89%8D%E7%8A%B6%E6%80%81"><span class="toc-number">2.39.</span> <span class="toc-text">查看当前状态</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%9F%A5%E7%9C%8B%E5%BD%93%E5%89%8D%E8%BF%9E%E6%8E%A5%E7%9A%84%E7%94%A8%E6%88%B7"><span class="toc-number">2.40.</span> <span class="toc-text">查看当前连接的用户</span></a></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/posts/adb47c67.html" title="MySQL常用语句"><img src= "" data-lazy-src="https://www.sxkawzp.cn/upload/2020/2/mysql1-12a849f2afe54669a6cc3259e9d380ac.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="MySQL常用语句"/></a><div class="content"><a class="title" href="/posts/adb47c67.html" title="MySQL常用语句">MySQL常用语句</a><time datetime="2022-04-10T18:46:44.000Z" title="发表于 2022-04-11 02:46:44">2022-04-11</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/posts/e8f88cd9.html" title="php json 处理gbk转码utf-8问题（ json_encode转换数组，值为null）"><img src= "" data-lazy-src="/img/default_list.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="php json 处理gbk转码utf-8问题（ json_encode转换数组，值为null）"/></a><div class="content"><a class="title" href="/posts/e8f88cd9.html" title="php json 处理gbk转码utf-8问题（ json_encode转换数组，值为null）">php json 处理gbk转码utf-8问题（ json_encode转换数组，值为null）</a><time datetime="2022-04-10T18:44:16.000Z" title="发表于 2022-04-11 02:44:16">2022-04-11</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/posts/9bca3d9a.html" title="宝塔WebHook拉取git命令"><img src= "" data-lazy-src="/img/default_list2.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="宝塔WebHook拉取git命令"/></a><div class="content"><a class="title" href="/posts/9bca3d9a.html" title="宝塔WebHook拉取git命令">宝塔WebHook拉取git命令</a><time datetime="2022-04-08T17:45:10.000Z" title="发表于 2022-04-09 01:45:10">2022-04-09</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/posts/6220e42c.html" title="Hexo使用ButterFly主题"><img src= "" data-lazy-src="/img/default_list.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Hexo使用ButterFly主题"/></a><div class="content"><a class="title" href="/posts/6220e42c.html" title="Hexo使用ButterFly主题">Hexo使用ButterFly主题</a><time datetime="2022-04-08T17:29:05.000Z" title="发表于 2022-04-09 01:29:05">2022-04-09</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/posts/eb656981.html" title="使用Hexo搭建博客"><img src= "" data-lazy-src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fgitee.com%2Fwangbowen97%2FBlogImgs%2Fraw%2Fmaster%2FpostImages%2FHexoCover.jpg&amp;refer=http%3A%2F%2Fgitee.com&amp;app=2002&amp;size=f9999,10000&amp;q=a80&amp;n=0&amp;g=0n&amp;fmt=auto?sec=1652059164&amp;t=ac7f746ad7621718ece964ce547ba635" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="使用Hexo搭建博客"/></a><div class="content"><a class="title" href="/posts/eb656981.html" title="使用Hexo搭建博客">使用Hexo搭建博客</a><time datetime="2022-04-07T21:39:46.000Z" title="发表于 2022-04-08 05:39:46">2022-04-08</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2021 - 2022 By 小灰灰</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div><div class="footer_custom_text">Hi, welcome to my <a target="_blank" rel="noopener" href="https://xiaohuihui.net/">blog</a>!</div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="translateLink" type="button" title="简繁转换">简</button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><a id="to_comment" href="#post-comment" title="直达评论"><i class="fas fa-comments"></i></a><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">本地搜索</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="is-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i><span>  数据库加载中</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div><hr/><div id="local-search-results"></div></div></div><div id="search-mask"></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="/js/tw_cn.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.umd.js"></script><script src="https://cdn.jsdelivr.net/npm/instant.page/instantpage.min.js" type="module"></script><script src="https://cdn.jsdelivr.net/npm/vanilla-lazyload/dist/lazyload.iife.min.js"></script><script src="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.js"></script><script src="/js/search/local-search.js"></script><script>var preloader = {
  endLoading: () => {
    document.body.style.overflow = 'auto';
    document.getElementById('loading-box').classList.add("loaded")
  },
  initLoading: () => {
    document.body.style.overflow = '';
    document.getElementById('loading-box').classList.remove("loaded")

  }
}
window.addEventListener('load',preloader.endLoading())</script><div class="js-pjax"><script>function loadValine () {
  function initValine () {
    const valine = new Valine(Object.assign({
      el: '#vcomment',
      appId: 'bfiqRSFKXN6o264vo900neYc-gzGzoHsz',
      appKey: '2SaEN1fWOUIqba7jlD1i9G9B',
      avatar: 'monsterid',
      serverURLs: 'https://bfiqrsfk.lc-cn-n1-shared.com',
      emojiMaps: "",
      path: window.location.pathname,
      visitor: false
    }, null))
  }

  if (typeof Valine === 'function') initValine() 
  else getScript('https://cdn.jsdelivr.net/npm/valine/dist/Valine.min.js').then(initValine)
}

if ('Valine' === 'Valine' || !true) {
  if (true) btf.loadComment(document.getElementById('vcomment'),loadValine)
  else setTimeout(loadValine, 0)
} else {
  function loadOtherComment () {
    loadValine()
  }
}</script></div><script src="/js/Lete.js"></script><script defer="defer" id="ribbon" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/canvas-ribbon.min.js" size="150" alpha="0.3" zIndex="-1" mobile="true" data-click="false"></script><script defer="defer" id="fluttering_ribbon" mobile="true" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/canvas-fluttering-ribbon.min.js"></script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>